package com.xuwang.service.impl;

import com.github.pagehelper.PageHelper;
import com.xuwang.dto.WorkLogDto;
import com.xuwang.mapper.WorkLogGMapper;
import com.xuwang.pojo.WorkLogG;
import com.xuwang.service.WorkLogServiceG;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WorkLogServiceGGImpl implements WorkLogServiceG {

    @Resource
    private WorkLogGMapper workLogGMapper;

    @Override
    public Map<String, Object> selectAll(Integer id ,
                                         String departmentName,
                                         String staffName,
                                         String logCreateTime,
                                         int page, int limit) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(page,limit);
        map.put("code",500);
        map.put("msg","获取失败!");
        List<WorkLogDto> workLogDtos = workLogGMapper.selectAll(id,departmentName,staffName,logCreateTime);

        System.out.println("总条数是!!!==="+workLogDtos.size());
        if(workLogDtos!=null){
            map.put("code",200);
            map.put("msg","获取成功");
            map.put("count",workLogDtos.size());
            map.put("AllCount", workLogGMapper.selectAll(null,null,null,null).size());
            map.put("data",workLogDtos);
            return map;
        }
        return map;
    }

    @Override
    public Map<String, Object> logInsert(WorkLogG workLogG) {
        Map<String, Object> map = new HashMap<>();
        map.put("code",500);
        map.put("msg","提交失败!");
        if(workLogGMapper.LogInsert(workLogG)>0){
            map.put("code",200);
            map.put("msg","提交成功");
            map.put("data", workLogG);
            return map;
        }
        return map;
    }
}
